﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ADA.Business;
using ADA.Entity;

namespace ADA.Presentation.PRL.Trading
{
    public partial class UserPostDetailForm : Form
    {
        long postID;
        MainForm main;
        public UserPostDetailForm(MainForm Main, long PostID)
        {
            main = Main;
            postID = PostID;
            InitializeComponent();
        }

        private void UserPostDetailForm_Load(object sender, EventArgs e)
        {
            DataTable tblPost;
            string message;
            BOLTrading bolTrading = new BOLTrading();
            if (bolTrading.viewPostDetail(postID, out tblPost, out message) == true)
            {
                Post post = new Post();
                string province = "";
                string userName = "";
                string riceType = "";
                if (tblPost.Rows.Count == 1)
                {
                    post.ID = postID;
                    post.UserID = Convert.ToInt64(tblPost.Rows[0]["UserID"]);
                    post.Amount = Convert.ToInt64(tblPost.Rows[0]["Amount"]);
                    post.Price = Convert.ToInt32(tblPost.Rows[0]["Price"]);
                    post.Address = Convert.ToString(tblPost.Rows[0]["Address"]).Trim();
                    post.Date = Convert.ToDateTime(tblPost.Rows[0]["CreateDate"]);
                    post.Status = Convert.ToInt16(tblPost.Rows[0]["Status"]);

                    userName = Convert.ToString(tblPost.Rows[0]["UserName"]).Trim();
                    riceType = Convert.ToString(tblPost.Rows[0]["TypeName"]).Trim();
                    province = Convert.ToString(tblPost.Rows[0]["Province"]).Trim();
                }

                lblID.Text = post.ID.ToString();
                lblUserID.Text = post.UserID.ToString();
                lblUserName.Text = userName.ToString();
                lblRiceType.Text = riceType.ToString();
                lblAmount.Text = post.Amount.ToString();
                lblSellingPrice.Text = post.Price.ToString();
                lblAddress.Text = post.Address.ToString() + ", " + province;
                lblCreatedDate.Text = post.Date.ToString();
                lblStatus.Text = BOLCommon.getPostStatus(post.Status);
            }
            else
            {
                MessageBox.Show(message);
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            main.btnDeleteUserPost_Click(sender, e);
            this.Close();
        }
    }
}
